extends KinematicBody2D

onready var rightActor = get_parent().get_node("Swordmaster")
onready var anim = $AnimationPlayer
onready var pos = $Position2D

var float_text = preload("res://Prefabs/Effect/Float.tscn")
var hurt_effect = preload("res://Prefabs/Effect/Hurt.tscn")

func _ready() -> void:
	rightActor.connect("hurtTarget",self,"takeDamage")

func takeDamage():
	var ft = float_text.instance()
	ft.velocity = Vector2(rand_range(-50,50),-130)
	ft.gravity = Vector2(0,1.5)
	ft.modulate = Color(rand_range(0.1,1),rand_range(0.1,1),rand_range(0.1,1),1)
	ft.set_text(int(rand_range(-10,-20)))
	ft.mass = 200
	pos.add_child(ft)
	anim.play("Hurt")
	
	var he = hurt_effect.instance()
	pos.add_child(he)
	

